import { createMemoryHistory, createRouter } from 'vue-router'
import echartRoutes from './echarts'
import baiduMapRoutes from './baiduMap'

// const requireComponent = require.context('../views', true, /\.vue$/)
// let views= []
// requireComponent.keys().forEach((fileName) => {
//   console.log('fileName', fileName)
//   // 获取组件配置
//   const componentConfig = requireComponent(fileName).default;
//   console.log('componentConfig',componentConfig)
//    // 获取组件的 PascalCase 命名
//    const componentName = fileName
//    .replace(/^\.\/(.*)\.\w+$/, '$1')
//    .split('-')
//    .map(kebab => kebab.charAt(0).toUpperCase() + kebab.slice(1))
//    .join('');

//    console.log('componentName', componentName)

// let component = componentConfig.__file.replace('src', '@')
//    views.push(
//     {
//         name: componentName,
//         path: `/views/${componentName}`,
//         component
//         // component:  () => import(/* webpackChunkName: "views" */ component)
//     }
//    )
// })
// console.log('views',views)


const routes = [
    {
        name: '/',
        path: '/',
        redirect: '/home'
    },
    {
        name: 'home',
        path: '/home',
        component: () => import(/* webpackChunkName: "homeView" */ '@/views/homeView')
    },
    {
        name: 'about',
        path: '/about',
        component: () => import(/* webpackChunkName: "about" */ '@/views/aboutView')
    },
    ...echartRoutes,
    ...baiduMapRoutes
]

const router = createRouter({
    history: createMemoryHistory(),
    routes,
})

export default router
